﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FrenzDenWebSite.Business;
using System.Web.UI.HtmlControls;

namespace FrenzDenWebSite
{
    public partial class ViewsInterestForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies[SiteConstants.COOKIESTRINGPROFILE] == null)
            {
                Response.Redirect("~/Default.aspx?prev=ViewsInterest&showmsg=1");
            }

            if (!IsPostBack)
            {
                GetProfileViewInterest();
            }
        }

        private void GetProfileViewInterest()
        {
            using (DenStoreDataContext dataContext = new DenStoreDataContext())
            {
                long profileId = SiteCommon.DecryptSession(Request.Cookies[SiteConstants.COOKIESTRINGPROFILE].Value).ProfileID;
                var result = dataContext.GetProfileViewInterest(profileId);
                foreach (var item in result)
                {
                    txtReligion.Text = item.ReligionView;
                    ddlReligionPrivacy.SelectedValue = item.ReligionViewPrivacy.ToString();
                    txtPolitical.Text = item.PoliticalView;
                    ddlPoliticalPrivacy.SelectedValue = item.PoliticalViewPrivacy.ToString();
                    txtInspired.Text = item.PeopleInspired;
                    ddlInspiredPrivacy.SelectedValue = item.PeopleInspiredPrivacy.ToString();
                    txtFavQuote.Text = item.FavQuote;
                    ddlFavQuotePrivacy.SelectedValue = item.FavQuotePrivacy.ToString();
                    txtHobbies.Text = item.HobbiesInterest;
                    ddlHobbiesPrivacy.SelectedValue = item.HobbiesInterestPrivacy.ToString();
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            MessageBox msgbox = null;
            try
            {
                using (DenStoreDataContext dataContext = new DenStoreDataContext())
                {
                    long profileId = SiteCommon.DecryptSession(Request.Cookies[SiteConstants.COOKIESTRINGPROFILE].Value).ProfileID;
                    dataContext.UpdateProfileViewInterest(profileId, txtReligion.Text, Convert.ToInt16(ddlReligionPrivacy.SelectedValue),
                                                        txtPolitical.Text, Convert.ToInt16(ddlPoliticalPrivacy.SelectedValue),
                                                        txtInspired.Text, Convert.ToInt16(ddlInspiredPrivacy.SelectedValue),
                                                        txtFavQuote.Text, Convert.ToInt16(ddlFavQuotePrivacy.SelectedValue),
                                                        txtHobbies.Text, Convert.ToInt16(ddlHobbiesPrivacy.SelectedValue));
                    msgbox = new MessageBox("Successfully updated!");
                }
            }
            catch
            {
                msgbox = new MessageBox(SiteConstants.ERRORMSG);
            }

            msgboxpanel.InnerHtml = msgbox.ReturnObject();
        }
    }
}